# 批量移除Java文件的BOM字符

$javaFiles = Get-ChildItem -Path "src\main\java" -Filter "*.java" -Recurse
$count = 0

Write-Host "Found $($javaFiles.Count) Java files"

foreach ($file in $javaFiles) {
    $bytes = [System.IO.File]::ReadAllBytes($file.FullName)
    
    # 检查是否有BOM
    if ($bytes.Length -ge 3 -and $bytes[0] -eq 0xEF -and $bytes[1] -eq 0xBB -and $bytes[2] -eq 0xBF) {
        Write-Host "Removing BOM from: $($file.Name)"
        
        # 移除BOM字符
        $newBytes = $bytes[3..($bytes.Length-1)]
        [System.IO.File]::WriteAllBytes($file.FullName, $newBytes)
        $count++
    }
}

Write-Host "Processed $count files with BOM removed."